<template>
	<view class="content">
		
		<button class="size" v-for="site in Permissions" @tap="checkPermission(site)">{{site}}检查运行环境的权限</button>
		<view>{{cur}}</view>
		<button class="size" @tap="hasNotchInScreen">查询设备是否为刘海屏{{hasNotch}}</button>
		<button class="size" @tap="hasSplash">查询应用启动界面是否已关闭{{splash}}</button>
		<button class="size" @tap="isBackground">判断当前应用是否切换到后台{{isBack}}</button>
		<button class="size" @tap="isFullscreen">判断应用当前是否全屏模式显示{{isFull}}</button>
		<button class="size" @tap="setFullscreen">设置应用是否全屏显示</button>
		<button class="size" @tap="setStatusBarBackground">设置系统状态栏背景颜色</button>
		<button class="size" @tap="isImmersedStatusbar">判断当前是否为沉浸式状态栏模式{{remark}}</button>
		<button class="size" @tap="setCookie">设置Cookie值</button>
		<button class="size" @tap="getCookie">获取Cookie值</button>
		<button class="size" @tap="getSafeAreaInsets">获取应用的安全区域</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Permissions:["CAMERA","CONTACTS","GALLERY","LOCATION","NOTIFITION","RECORD","SHORTCUT"],
				cur:"",
				hasNotch:undefined,
				splash:undefined,
				isBack:undefined,
				isFull:undefined,
				remark:undefined
			}
		},
		onReady() {
		},
		methods: {
			checkPermission(site){
				var pp = plus.navigator.checkPermission(site);
					switch(pp){
						case 'authorized':
							plus.nativeUI.alert(`已开启${site}权限`);
						break;
						case 'denied':
							plus.nativeUI.alert(`已关闭${site}定位权限`);
						break;
						case 'undetermined':
							plus.nativeUI.alert(`未确定${site}权限`);
						break;
						case 'unknown':
							plus.nativeUI.alert(`无法查询${site}权限`);
						break;
						default:
							plus.nativeUI.alert(`不支持${site}权限`);
						break;
					}
			},
			pickMore(){
				console.log("从相册中选择多张图片:");
				plus.gallery.pick(function(e) {
					for (var i in e.files) {
						console.log(e.files[i]);
					}
				}, function(e) {
					console.log("取消选择图片");
				}, {
					filter: "image",
					multiple: true
				});
			},
			save(){
				plus.gallery.save( "_doc/1651807216-origin-IMG_7168.PNG" , function () {
					console.log( "保存图片到相册成功" );
				},function(e){
					console.log( "fail=>",e );
				});
			},
			hasNotchInScreen(){
				this.hasNotch = plus.navigator.hasNotchInScreen();
			},
			hasSplash(){
				this.splash = plus.navigator.hasSplashscreen();
			},
			isBackground(){
				this.isBack = plus.navigator.isBackground()
			},
			isFullscreen(){
				this.isFull = plus.navigator.isFullscreen();
			},
			setFullscreen(){
				plus.navigator.setFullscreen(true);
			},
			setStatusBarBackground(){
				// 沉浸式状态不生效
				plus.navigator.setStatusBarBackground('#FF0000');
			},
			isImmersedStatusbar(){
				this.remark = plus.navigator.isImmersedStatusbar();
			},
			setCookie(){
				plus.navigator.setCookie('http://www.dcloud.io/', 'test=123; expires=Friday,24-Jan-2015 16:24:36 GMT; path=/');
			},
			getCookie(){
				const msg = plus.navigator.getCookie('http://www.dcloud.io/');
				console.log(msg)
			},
			getSafeAreaInsets(){
				const info = plus.navigator.getSafeAreaInsets();
				console.log("info=>",info)
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.size {
		margin: 30rpx 0;
	}
</style>
